<!--
 * @Author: Lakeiedward
 * @Date: 2022-02-26 23:48:36
 * @LastEditTime: 2022-02-27 01:23:04
 * @FilePath: \demo2\src\components\three.vue
-->
<template>
  <div>
    <div id="main"></div>
  </div>
</template>
<script>
import * as echarts from "echarts";
export default {
  props: ["receptions"],
  data() {
    return {
      my: null,
    };
  },
  watch: {
    receptions: {
      handler: function () {
        this.my.dispose();
        this.aoo();
      },
    },
    deep: true,
  },
  created() {},
  mounted() {
    this.aoo();
    this.$root.$on("www", (index) => {
      this.receptions.splice(index, 1);
      const ww = JSON.parse(localStorage.getItem("bbb"));
      ww.splice(index, 1);
      const kk = JSON.stringify(ww);
      localStorage.setItem("bbb", kk);
    });
  },
  methods: {
    aoo() {
      var chartDom = document.getElementById("main");
      var myChart = echarts.init(chartDom);
      this.my = myChart;
      var option;
      option = {
        title: {
          text: "Referer of a Website",
          subtext: "Fake Data",
          left: "center",
        },
        tooltip: {
          trigger: "item",
          formatter: "{b}: {c}<br />所占百分比:{d}%",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "50%",
            data: this.receptions,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };

      option && myChart.setOption(option);
    },
  },
};
</script>
<style scoped lang='scss'>
#main {
  height: 400px;
}
</style>